{%extends file='layout/layout.html' %}
{%block name="content"%}
<div class="hastable">

    <div style="margin-bottom: 10px">
        <label class="btn btn-success btn-sm" onclick=goback("/admin/createactivity")><i class="fa fa-plus"></i>创建活动</label>
        <label class="btn btn-danger btn-sm" onclick="delall()"><i class="fa fa-remove"></i>批量删除</label>
    </div>

    <div style="margin-bottom: 10px">
        <label style="margin-right: 10px">活动名称:</label><input style="margin-right: 10px" type="text" name="search" value="{%$search|default:''%}">
        <label style="margin-right: 10px">适合年龄:</label><input style="margin-right: 10px;width: 100px" value="{%$minage|default:''%}" type="text" name="minage"><label style="margin-right: 10px">~</label><input value="{%$maxage|default:''%}" style="margin-right: 10px;width: 100px" type="text" name="maxage">
        <label style="margin-right: 10px">活动时间:</label><input readonly class="datepicker" style="margin-right: 10px;width: 100px" type="text" value="{%$starttime|default:''%}" name="starttime"><label style="margin-right: 10px">~</label><input readonly class="datepicker" value="{%$endtime|default:''%}" style="margin-right: 10px;width: 100px" type="text" name="endtime">
        <label class="btn btn-success btn-sm" onclick="doserch()"><i class="fa fa-search"></i>检索</label>
        <label class="btn btn-success btn-sm" onclick="reset()"><i class="fa fa-remove"></i>清空</label>
    </div>

    <table>
        <thead>
        <tr>
            <th><input value="check_none" onclick="checkall(this)" class="submit" type="checkbox">
            </th>
            <th>活动名称</th>
            <th>适合年龄</th>
            <th>活动时间</th>
            <th>已报名家庭/招募家庭</th>
            <th>积分兑换</th>
            <th style="width:132px">操作</th>
        </tr>
        </thead>
        <tbody>
        {%if $data|@count neq 0 %}
        {%foreach $data as $key=>$value%}
        <tr class="{%if $key%2 neq 0 %}even{%else%}odd{%/if%}">
            <td class="center"><input value="{%$value.id%}" name="list" class="checkbox" type="checkbox"></td>
            <td>{%$value.activityname|default:''%}</td>
            <td>{%$value.minage|default:''%}~{%$value.maxage|default:''%}</td>
            <td>
                {%$value.starttime|date_format:'%Y-%m-%d'|default:''%}~{%$value.endtime|date_format:'%Y-%m-%d'|default:''%}
            </td>
            <td>{%$value.joinnum|default:0%}/{%$value.maxnum|default:0%}{%if $value.joinnum neq 0%}<a style="margin-left: 10px;cursor: pointer" target="_blank" href="/admin/downactivity/{%$value.id%}"><i class="fa fa-download"></i></a>{%/if%}</td>
            <td>{%$value.maxintegral|default:''%}</td>
            <td>
                <a class="btn_no_text btn ui-state-default ui-corner-all tooltip" href="/admin/createactivity/{%$value.id%}">
                    <span class="ui-icon ui-icon-wrench"></span>
                </a>
                <a class="btn_no_text btn ui-state-default ui-corner-all tooltip" attrid="{%$value.id%}" onclick="rmrow(this)" href="javascript:void(0)">
                    <span class="ui-icon ui-icon-circle-close"></span>
                </a>
            </td>
        </tr>
        {%/foreach%}
        {%else%}
        <tr class="even">
            <td colspan="7" style="text-align: center">无内容</td>
        </tr>
        {%/if%}

        </tbody>

    </table>

    <ul style="width:50%;margin: 0 auto;text-align: center" id="pagination"></ul>

</div>
<div class="clearfix"></div>

{%/block%}
{%block name="js" append%}
<script type="text/javascript">

    $(function () {
        init()
    })
    function init() {
        $(".datepicker").datepicker({
            dateFormat: "yy-mm-dd",
            showOtherMonths: true,
            selectOtherMonths: true,
            showButtonPanel: true,
            showOn: "both",
            buttonImageOnly: true,
            buttonText: "",
            changeMonth: true,
            changeYear: true
        });
        {%if $data|@count neq 0 %}
        $("#pagination").twbsPagination("destroy");
        $('#pagination').twbsPagination({
            startPage: parseInt("{%$page|default:1%}"),
            initiateStartPageClick: false,
            totalPages: parseInt("{%$total%}"),
            visiblePages: 10,
            first: '首页',
            last: '尾页',
            prev: '«',
            next: '»',
            paginationClass: '',
            nextClass: 'next',
            prevClass: '',
            lastClass: '',
            firstClass: '',
            pageClass: '',
            activeClass: 'active',
            disabledClass: 'previous-off',
            anchorClass: '',
            onPageClick: function (event, pager) {

                var data = {page:pager};
                window.location.href = '/admin/activity/' + $.base64.btoa(JSON.stringify(data));

            }

        });
        {%/if%}
    }
    function doserch() {

        var search = $("input[name='search']").val();
        var minage = $("input[name='minage']").val();
        var maxage = $("input[name='maxage']").val();
        var starttime = $("input[name='starttime']").val();
        var endtime = $("input[name='endtime']").val();
        var data = {
            search: escape($.trim(search)),
            minage: minage,
            maxage: maxage,
            starttime: starttime,
            endtime: endtime,
            page: parseInt("{%$page|default:1%}")
        };
        window.location.href = '/admin/activity/' + $.base64.btoa(JSON.stringify(data));

    }
    function reset() {
        $("input[name='search']").val('');
        $("input[name='minage']").val('');
        $("input[name='maxage']").val('');
        $("input[name='starttime']").val('');
        $("input[name='endtime']").val('');
        window.location.href = '/admin/activity';
    }
    function rmrow(obj) {
        var id= obj.getAttribute('attrid');
       $.post('/api/deleteactivity.json',{id:id},function (data, textStatus, jqXHR) {
          if(jqXHR.status==200){
              showmsg(jqXHR.responseText, 1);
              dorefulsh()

          }else{
              showmsg(jqXHR.responseText, 2);
          }
       });




    }
    function delall() {
        var id=[];
        $("input[name='list']").each(function (k,v) {
            if(v.checked){
                id.push(parseInt(v.value))
            }
        })
        if(id.length>0){
            $.post('/api/deleteactivity.json',{id:id.join(',')},function (data, textStatus, jqXHR) {
                if(jqXHR.status==200){
                    showmsg(jqXHR.responseText, 1);
                    dorefulsh()

                }else{
                    showmsg(jqXHR.responseText, 2);
                }
            });
        }else{
            showmsg('请选择要删除的活动', 2);
        }


    }

</script>
{%/block%}
